<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Date" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>JSTL的使用</title>
</head>
<body>
    <h1>通用标签:set,out,remove</h1>
    <h3>set:向域中设置数据</h3>
    <c:set var="username" value="张三"></c:set>
    <c:set var="address" value="北京"></c:set>
    <c:set var="content" value="<script type='text/javascript'>alert('欢迎使用jstl')</script>"></c:set>

    ${username}

    <h3>out:输出数据</h3>

    <c:out value="${address}"></c:out>
    <c:out value="${content}"></c:out>
    <h3>remove</h3>
    <c:remove var="address"></c:remove>

    <h1>if、choose</h1>
    <c:if test="${empty user}">
        没有登录
    </c:if>

    <c:set var="score" value="80"></c:set>
    <c:choose>
        <c:when test="${score>=90 }">优秀</c:when>
        <c:when test="${score>=80 }">良好</c:when>
        <c:when test="${score>=70 }">中等</c:when>
        <c:when test="${score>=60 }">及格</c:when>
        <c:otherwise>不及格</c:otherwise>
    </c:choose>

    <h1>foreach</h1>

    <%
        List<String> cities=new ArrayList<String>();
        cities.add("北京");
        cities.add("上海");
        cities.add("杭州");
        cities.add("深圳");
        pageContext.setAttribute("cities", cities);
    %>

    <c:forEach  items="${cities}" var="c" varStatus="vs">
        ${c} --${vs.index}--${vs.count}
    </c:forEach>
    <br/>
    <c:forEach var="n" begin="1" end="10">
        ${n}
    </c:forEach>

    <%
        pageContext.setAttribute("mydate", new Date());
    %>
    <fmt:formatDate value="${mydate}" pattern="yyyy-MM-dd"></fmt:formatDate>

</body>
</html>
